<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<div class="row stu-info-title">
	<div class="col-md-2"></div>
	<div class="col-md-8">
		<div class="row">
			<div class="col-md-12">
				<label for="">添加学生</label>
			</div>
		</div>
		<div class="row">
			<div class="col-md-3"></div>
			<div class="col-md-6">
				<input type="text" class="form-control" name="searchStudent" placeholder="学号/姓名">
			</div>
			<div class="col-md-3">
				<button class="btn btn-primary" id="searchStudent">搜索</button>
			</div>
		</div>
		<div class="row">
			<!--将要添加学生列表-->
			<div class="col-md-12">
				<table class="table table-hover correct-show">
					<thead>
						<tr>
							<th>序号</th>
							<th>学号</th>
							<th>姓名</th>
							<th>操作</th>
						</tr>
					</thead>
					<tbody id="searchStudentList">
					</tbody>
				</table>
			</div>
		</div>
	</div>
	
	<div class="col-md-2"></div>
</div>
<script>
$(function() {
	$("#searchStudent").click(seachStudentEvent);
});
var seachStudentEvent = function(){
	var keywords=$("input[name='searchStudent']").val();
	if(keywords==""){
		alert("请输入搜索信息");
		return;
	}
	var json={
			keywords:keywords,
			classId:data.data.classView.id
	};
	$.get(CONTEXT_PATH+"cscontrol/searchListData", {
		data : JSON.stringify(json)
	},function(data) {
		if(data.status=="success"){
			var searchStudentList = $("#searchStudentList");
			searchStudentList.empty();
    		var s="";
    		var students=data.data.list;
    		for(var i=0;i<students.length;i++){
    			var item=students[i];
    			s+="<tr>";
    			s+="<th scope=\"row\">"+(i+1)+"</th>";
    			s+="<td title=\""+item.studentCode+"\">"+item.studentCode+"</td>";
    			s+="<td title=\""+item.name+"\">"+item.name+"</td>";//<input type=\"checkbox\" name=\"studentId\" value=\""+item.id+"\" />
    			if(item.hasJoined==1){
	    			s+="<td>已添加</td>";
    			}else{
        			s+="<td><button onclick=\"addStudent("+item.id+")\" class=\"btn btn-primary\">添加</button></td>";
    			}
    			s+="</tr>";
    		}
    		searchStudentList.append(s);
		}else{
			alert(data.message);
		}
	}); 
}
var addStudent= function(studentId){
	var json={
			classId:data.data.classView.id,
			studentId:studentId
	}
	$.post(CONTEXT_PATH+"cscontrol/ajaxCreate", {
		data : JSON.stringify(json)
	} ,function(data) {
		if(data.status=="success"){
			seachStudentEvent();
		}else{
			alert(data.message);
		}
	});
	
}
</script>